package tech.summerly.weather

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.Observer
import kotlin.coroutines.experimental.suspendCoroutine

suspend fun <T> LiveData<T>.await(): T? = suspendCoroutine {
    val observer = object : Observer<T> {
        override fun onChanged(t: T?) {
            removeObserver(this)
            it.resume(t)
        }
    }
    observeForever(observer)
}